	//打开数据库
	var indexedDB=window.indexedDB||window.webkitIndexedDB||window.mozIndexedDB||window.msIndexedDB;
	var dbname="talkDB";
	var dbversion=1;
	var storename="talk";
	var mydb=null;
	init();
	
	//数据库初始化
	function init()
	{
		var dbrequest=indexedDB.open(dbname,dbversion);
		dbrequest.onsuccess=function(e)
		{
			mydb=e.target.result;
			
		};
		dbrequest.onerror=function(e)
		{
			alert("数据库连接失败！");
		};
		dbrequest.onupgradeneeded=function(e)
		{
			mydb=e.target.result;
			if(!mydb.objectStoreNames.contains(storename))
			{	
				var optionalParameters={keyPath:"id",autoIncrement:true};
				var objectStore=mydb.createObjectStore(storename,optionalParameters);
				//alert("对象仓库创建成功");
			}
			var tx=e.target.transaction;
			//alert("数据库版本更新成功！版本："+e.oldVersion+"=>版本"+e.newVersion);
		};
	}

	//数据保存
	function saveData()
	{
		//1.获取数据
		var tit=document.getElementById("tit").value;
		var cot=document.getElementById("con").value;
		var cat=document.getElementsByName("cat");
		var xingzhi="";
		var mydate=new Date();
		var year=mydate.getFullYear();
		var month=mydate.getMonth()+1;
		var day=mydate.getDate();
		var time=year+"-"+month+"-"+day;
		for(var i=0;i<cat.length;i++)
		{
			if(cat[i].checked==true)
			{
				xingzhi=cat[i].value;
				break;
			}
		}
		var comment={
			title:tit,
			content:cot,
			charac:xingzhi,
			publictime:time
		};
		var tx=mydb.transaction(storename,'readwrite');
		tx.oncomplete=function()
		{
			alert("发布成功！");
			window.open("bbs_contentlist.html");
		}
		tx.onabort=function()
		{
			alert("数据保存失败！");
		}
		var objectStore=tx.objectStore(storename);
		objectStore.add(comment);
		
	}
	
	//展示数据
	function showdata()
	{
		var showBody=document.getElementById("showBody");
		showBody.innerHTML="";
		var tx=mydb.transaction(storename,'readonly');
		var objectStore=tx.objectStore(storename);
		var request=objectStore.openCursor();
		request.onsuccess=function(e)
		{
			var cursor=e.target.result;
			var i=-1;//设置动态打印行的顺序--排队
			if(cursor)
			{
				
				var tableRow=showBody.insertRow(i);
				tableRow.insertCell(0).innerHTML=cursor.value.title;
				tableRow.insertCell(1).innerHTML=cursor.value.charac;
				tableRow.insertCell(2).innerHTML=cursor.value.publictime;
				tableRow.insertCell(3).innerHTML="<button onclick='checkcontent(this.parentNode.parentNode)' class='button1' target='blank'>查看帖子内容</button>";
				cursor.continue();
			}
			else
			{
				console.log("检索结束");
			}
		}
		request.onerror=function(e)
		{
			console.log("检索失败");
		}
		
	}
	//帖子内容跳转
	function checkcontent(e)
	{
		var tit=e.cells[0].innerText;
		var rindex=e.rowIndex;
		var tx=mydb.transaction(storename,'readwrite');
		var objectStore=tx.objectStore(storename);
		var reqget=objectStore.get(rindex);
		reqget.onsuccess=function()
		{
			var content=reqget.result.content;
			sessionStorage.setItem("content",content);
			window.open("bbs_content.html");
			
		}
		reqget.onerror=function()
		{
			alert("error!");
		}
	}
	//内容页面加载对应内容
	function show()
	{
		var neirong=document.getElementById("neirong");
		var content=sessionStorage.getItem("content");
		neirong.innerText=content;
	}





function gettocontentlist()
{
	window.open("bbs_contentlist.html");
}


function clr()
{
	if(confirm("确认重置当前内容吗?"))
	{
		location.reload();
	}
}
	

	

